#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	if(n<m)
	{
		cout<<"NO"<<endl;
	}
	else 
	{
		int j=0;
		for(int i=0;i<m;i++)
		{
			if(j>=n)
			{
				cout<<"NO"<<endl;
				return;
			}
			if(i==m-1)
			{
				if(t[i]=='1')
				{
					int c1=0;
					while(j<n)
					{
						if(s[j]=='1')c1++;
						j++;
					}
					if(c1%2)
					{
						cout<<"YES"<<endl;
						return ;
					}
					else
					{
						cout<<"NO"<<endl;
						return ;
					} 
				}
				else 
				{
					if(j==n-1&&s[j]=='0')
					{
						cout<<"YES"<<endl;
						return ;
					}
					else 
					{
						int c1=0;
						while(j<n)
						{
							if(s[j]=='1')c1++;
							j++;
						}
						if(c1%2)
						{
							cout<<"NO"<<endl;
							return ;
						}
						else
						{
							cout<<"YES"<<endl;
							return ;
						}
					}
				}
			}
			if(t[i]=='0')
			{
				if(s[j]=='0')
				{
					j++;
				}
				else 
				{
					j++;
					int c1=1;
					while(j<n&&c1!=2)
					{
						if(s[j]=='1')c1++;
						j++;
					}
                    if(j>=n)
                    {
                        cout<<"NO"<<endl;
                        return;
                    }
				}
			}
			if(t[i]=='1')
			{
				if(s[j]=='1')
				{
					j++;
				}
				else 
				{
					j++;
					int c1=0;
					while(j<n&&c1!=1)
					{
						if(s[j]=='1')c1++;
						j++;
					}
                    if(j>=n)
                    {
                        cout<<"NO"<<endl;
                        return;
                    }
				}
			}
		}
	}
}
signed main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	int T=1;
	//cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}